package com.eh.model;

import com.eh.collection.MapUtil;

/**
 * Created by David Li on 2016/7/4.
 */
public class RespUtil<T> {

    public AbstractResponse assembleResponse(String message, T t) {
        ResponseWrapper responseWrapper = new ResponseWrapper();
        responseWrapper.setResultCode("0");
        responseWrapper.setSuccess(true);
        responseWrapper.setMessage(message);
        try {
            responseWrapper.setResults(new MapUtil<T>().convert2Map(t));
        } catch (Exception e) {
            throw new RuntimeException("Error occurs when JavaBean transfer to Map.", e);
        }
        return responseWrapper;
    }

    public AbstractResponse assembleResponse(String resultCode, String message) {
        ResponseWrapper responseWrapper = new ResponseWrapper();
        responseWrapper.setResultCode(resultCode);
        responseWrapper.setSuccess(false);
        responseWrapper.setMessage(message);
        return responseWrapper;
    }
}
